package com.yxp.offer;

/**
 * @author : yang.xp
 * @date : 2021/9/4 17:52
 * @description : 剑指 Offer 03. 数组中重复的数字
 */
public class Problem03 {

    public static void main(String[] args) {
        Problem03 problem03 = new Problem03();
        System.out.println(problem03.findRepeatNumber3(new int[]{2, 3, 1, 0, 2, 5, 3}));
    }

    public int findRepeatNumber3(int[] nums) {
        int temp;
        // 把这个数放在对应的位置上
        for (int i = 0; i < nums.length; i++) {
            while (nums[i] != i) {
                if (nums[i] == nums[nums[i]]) {
                    return nums[i];
                }
                temp = nums[i];
                nums[i] = nums[temp];
                nums[temp] = temp;
            }
        }
        return -1;
    }

//    1 3 2 0
//    3 1 2 0
//    0 1 2 3
}
